#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: zhuo
@Software: PyCharm
@File: tQWorkbenchForm.py
@Time: 2024/1/18 10:27
@Function：ctQWorkbenchForm：自定义工作台界面类
"""

from PySide6.QtWidgets import *
from PySide6.QtGui import QPixmap, QTextCursor
from tUI.tQAlarmBox import ctQAlarmBox
from tUI.tQBlower import ctQBlower
from tUI.tQGridTitle import ctQGridTitle
from tUI.tQLoginBox import ctQLoginBox
from tUI.tQStateBox import ctQStateBox

RES_PATH = './ico/'                    # 资源文件基准地址
BLOWER_ICON = RES_PATH + "blower.png"  # 风机图标路径
TITLE_ICON = RES_PATH + "cosmo.png"    # 标题图标路径
COSMO_BLUE = "#005AAA"                 # 卡奥斯蓝
HAIER_BLUE = "#1296DB"                 # 海尔蓝


class ctQWorkbenchForm(QHBoxLayout):
    """
    自定义工作台界面类
    """

    # 初始化
    def __init__(self, widget, dicParaMsg):
        # 继承自父类
        super(ctQWorkbenchForm, self).__init__()
        # 参数信息
        self.dicParaMsg = dicParaMsg
        # 所在的widget
        self.workbenchTab = widget
        # 调用
        self.__f_workbenchLayout()

    # 工作台界面布局函数
    def __f_workbenchLayout(self):
        """
        function:  工作台界面布局函数
              in:  None
             out:  None
          return:  None
          others:  Workbench Form Layout Func
        """
        # 总体布局:：垂直布局
        self.mainWorkbenchLayout = QVBoxLayout()
        # 创建标题
        self.title = ctQGridTitle(160, 60, HAIER_BLUE)
        # 设置标题文本
        self.title.f_setTitle("变频器测控系统")
        # 设置标题图标
        self.title.f_setIcon(QPixmap(TITLE_ICON))

        # <editor-fold desc="创建布局">
        # 设置总布局
        self.workbenchTab.setLayout(self.mainWorkbenchLayout)
        # title下方的总布局 : 水平布局
        underLayout = QHBoxLayout()
        # 左侧布局：登录框+报警框：垂直布局
        leftLayout = QVBoxLayout()
        # 中间布局：风机+状态框：垂直布局
        middleLayout = QVBoxLayout()
        # 右侧布局：系统日志：垂直布局
        rightLayout = QVBoxLayout()
        # </editor-fold>

        # <editor-fold desc="左侧登录框+报警信息提示框控件">
        # 创建登录框
        self.loginBox = ctQLoginBox()
        # 创建报警信息提示框
        self.alarmBox = ctQAlarmBox()
        # 添加登录框
        leftLayout.addWidget(self.loginBox)
        # 添加报警信息提示框
        leftLayout.addWidget(self.alarmBox)
        # </editor-fold>

        # <editor-fold desc="中间布局控件">
        # 自定义状态栏控件
        self.stateBox = ctQStateBox(self.dicParaMsg)
        # 设置状态栏控件的最小高度
        self.stateBox.setMinimumHeight(50)
        # 设置状态栏控件的布局行为
        self.stateBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        # 自定义风机控件，设置定时器转动间隔、转动间隔、转速
        self.blower = ctQBlower(msec=10, rotate_angle=1, speed=800)
        # 自定义风机控件设置图标
        self.blower.setPixmap(QPixmap(BLOWER_ICON))
        # 自定义风机控件设置布局行为
        self.blower.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        # 创建弹簧控件
        spacer = QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Preferred)
        # 中间布局添加控件
        middleLayout.addWidget(self.blower)
        middleLayout.addItem(spacer)
        middleLayout.addWidget(self.stateBox)

        # </editor-fold>

        # <editor-fold desc="右侧系统日志控件">
        # 创建格栅布局
        gridLayout = QGridLayout()
        # 创建标签控件
        lblSystemLog = QLabel("系统日志")
        lblSystemLog.setStyleSheet("font-family: Microsoft YaHei;font-size: 12pt;font-weight:bold;")
        # 创建弹簧控件
        spacer = QSpacerItem(200, 20, QSizePolicy.Expanding, QSizePolicy.Fixed)
        # 格栅布局中添加控件
        gridLayout.addItem(spacer, 0, 0)
        gridLayout.addWidget(lblSystemLog, 0, 1)
        gridLayout.addItem(spacer, 0, 2)
        # 创建多行文本框控件
        self.txtSysLog = QPlainTextEdit()
        self.txtSysLog.setStyleSheet(f" color:{HAIER_BLUE};font-size: 10pt;font-weight:bold;")
        # QPlainText()取消光标
        self.txtSysLog.setTextCursor(QTextCursor())
        # 右侧布局中添加控件
        rightLayout.addLayout(gridLayout)
        rightLayout.addWidget(self.txtSysLog)
        # </editor-fold>

        # title下方的总布局添加控件
        underLayout.addLayout(leftLayout)
        underLayout.addLayout(middleLayout)
        underLayout.addLayout(rightLayout)
        # 总布局添加控件
        self.mainWorkbenchLayout.addWidget(self.title)
        self.mainWorkbenchLayout.addLayout(underLayout)
